//1184. 公交站间的距离
//思路：先把整个数组整体遍历加一遍，记为x
//再把start到destion相加一遍，记为y
//最后用x-y 与 y 取小返回，x-y是逆序相加的结果


#include <vector>
#include <algorithm>
using namespace std;

class Solution {
public:
    int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {
        if(start > destination)
            swap(start, destination);

        int x = 0, y = 0;
        for(int i = 0; i < distance.size(); ++i)
        {
            x += distance[i];
        }
        for(int i = start; i < destination; ++i)
        {
            y += distance[i];
        }

        return min(x-y, y);
    }
};